package cn.edu.njust.alg.leetcode;

import cn.edu.njust.alg.ArrayUtils;

public class Leetcode_189_rotate_array {

	/*
	 * Rotate an array of n elements to the right by k steps.
	 * 
	 * For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated
	 * to [5,6,7,1,2,3,4].
	 * 
	 * Note: Try to come up as many solutions as you can, there are at least 3
	 * different ways to solve this problem.
	 */
	public static void rotate(int[] nums, int k) {
		int[] tmp = nums.clone();
		for (int i = 0; i < nums.length; i++) {
			tmp[(i + k) % nums.length] = nums[i];
		}
		System.arraycopy(tmp, 0, nums, 0, nums.length);
	}

	public static void swap(int[] array, int index1, int index2) {
		int temp = array[index1];
		array[index1] = array[index2];
		array[index2] = temp;
	}

	public static void main(String[] args) {
		int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
		rotate(nums, 3);
		ArrayUtils.printArray(nums);

	}

}
